package com.siam.package_mall;

import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;

import java.util.Arrays;
import java.util.stream.Collectors;

//@EnableHystrix
//@EnableHystrixDashboard
@EnableCircuitBreaker
@EnableFeignClients("com.siam")
@EnableEurekaClient
@SpringBootApplication(scanBasePackages = "com.siam", exclude = {RocketMQAutoConfiguration.class})
@MapperScan(basePackages = {"com.siam.**.mapper"})
public class MallApplication
{
    public static void main(String[] args)
    {
        // Elasticsearch与Redis有冲突，启动时elasticsearchClient无法注入，需要配置此项代码
        System.setProperty("es.set.netty.runtime.available.processors","false");
        ConfigurableApplicationContext app = SpringApplication.run(MallApplication.class, args);

        ConfigurableEnvironment environment = app.getEnvironment();

        System.out.println("========== ACTIVE PROFILE ==========");
        System.out.println("Active profile: " + Arrays.toString(environment.getActiveProfiles()));
        System.out.println("========== CONFIG LOCATIONS ==========");
        for (String location : environment.getPropertySources().stream()
                .map(PropertySource::getName)
                .filter(name -> name.contains("application"))
                .collect(Collectors.toList())) {
            System.out.println(location);
        }

    }
}